package com.scpii.json.rpc;

import java.io.UnsupportedEncodingException;

import org.apache.http.Header;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;

import com.scpii.json.JSONException;

/**
 * Provides a HttpEntity for json content
 */
class JSONEntity extends StringEntity {
	/**
	 * Basic constructor
	 * 
	 * @param jsonObject
	 * @throws UnsupportedEncodingException
	 * @throws JSONException
	 */
	public JSONEntity(String jsonRequest) throws UnsupportedEncodingException {
		super(jsonRequest);
	}

	/**
	 * Constructor with encoding specified
	 * 
	 * @param jsonObject
	 * @param encoding
	 *            Chosen encoding from HTTP.UTF_8, HTTP.UTF_16 or ISO_8859_1 or
	 *            any other supported format
	 * @throws UnsupportedEncodingException
	 * @throws JSONException
	 */
	public JSONEntity(String jsonRequest, String encoding)
			throws UnsupportedEncodingException {
		super(jsonRequest, encoding);
		setContentEncoding(encoding);
	}

	@Override
	public Header getContentType() {
		return new BasicHeader(HTTP.CONTENT_TYPE, "application/json-rpc");
	}
}
